package time;
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
@SuppressWarnings("serial")
public class b extends JFrame {
    private JTextField  jtfInvestmentAmount = new JTextField();
    private JTextField  jtfYears = new JTextField();
    private JTextField  jtfMonthlyInterestRate = new JTextField();
    private JTextField  jtfFutureValue = new JTextField();
    private JButton jbtCalculate = new JButton("Calculate");
    public b()
    {
    	JPanel p1 = new JPanel(new GridLayout(4,2));
    	p1.add(new JLabel("Investment Amount"));
    	p1.add(jtfInvestmentAmount);
    	p1.add(new JLabel("Years"));
    	p1.add(jtfYears);
    	p1.add(new JLabel("Monthly interest rate"));
    	p1.add(jtfMonthlyInterestRate);
    	p1.add(new JLabel("Future value"));
    	p1.add(jtfFutureValue);
    	p1.setBorder(new TitledBorder("Enter Investment amount,years and monthly interest rate"));
    	JPanel p2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    	p2.add(jbtCalculate);
    	add(p1,BorderLayout.CENTER);
    	add(p2,BorderLayout.SOUTH);
    	jbtCalculate.addActionListener(new ButtonListener());
    }
    private class ButtonListener implements ActionListener{
    	
    	public void actionPerformed(ActionEvent e){
    		double InvestmentAmount = Double.parseDouble(jtfInvestmentAmount.getText());
    		int Years = Integer.parseInt(jtfYears.getText());
    		double Rate = Double.parseDouble(jtfMonthlyInterestRate.getText());
    		double FutureValue = InvestmentAmount *Math.pow((1 + Rate),Years*12);
    		jtfFutureValue.setText(String .format("%.2f",FutureValue));
    	}
    }
	public static void main(String[] args) {
		// TODO Auto-generated method stub
       JFrame frame = new b();
       frame.pack();
       frame.setTitle("Investment Calculator");
      // frame.setLocationRelativeTo(null);
      // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame.setVisible(true);
	}
    
}
